#include <stdio.h>
#include <stdlib.h>

typedef struct node {
	int num;
	struct node *next;
} node;

void my_insert(node *head, int input);
void my_print(node *head);

int main() {
	node *head1 = (node *)malloc(sizeof(node));
	node *head2 = (node *)malloc(sizeof(node));
	head1->next = NULL;
	head2->next = NULL;

	int inputNum = 0;

	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &inputNum);
		if (inputNum > 0) {
			my_insert(head1, inputNum);
		} else {
			my_insert(head2, inputNum);
		}
	}

//	while (scanf("%d", &inputNum) != EOF) {
//		if (inputNum > 0) {
//			my_insert(head1, inputNum);
//		} else {
//			my_insert(head2, inputNum);
//		}
//	}

	my_print(head1);
	printf("\n");
	my_print(head2);

//	my_destroy(head1);
//	my_destroy(head2);
	return 0;
}

void my_insert(node *head, int input) {
	node *p = (node *)malloc(sizeof(node));

	node *q = head->next;
	node *qold = head;

	while (q != NULL && q->num < input) {
		qold = q;
		q = q->next;
	}
	p->next = q;
	p->num = input;
	qold->next = p;
}

void my_print(node *head) {
	node *p = head->next;
	while (p != NULL) {
		if (p == head->next) {
			printf("%d", p->num);
		} else {
			printf("->%d", p->num);
		}
		p = p->next;
	}
}

